<!DOCTYPE html>
<html lang="en">
<head>
    <title>积分商城</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <script src="/js/jquery/jquery.min.js"></script>
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css" />
    <link rel="stylesheet" href="/css/style.css" />
    <link rel="stylesheet" href="/css/reset.css" />
    <link rel="stylesheet" href="/css/myProfiles.css" />
    <link rel="stylesheet" href="/css/shop.css" />
    <script src="/js/plugins/jrender/jrender.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog/dialog.css">
    <script src="/js/plugins/dialog/dialog.min.js"></script>
    <script src="/js/common.js"></script>
    <script type="text/javascript">


        $(function () {
            // 页面翻页变量
            var currentPage = 1;
            var pages;
            var products;


            // 发送ajax请求获得所有已经上架的商品
            $.get("/products",{state:1,pageSize:4},function (data) {
                console.log(data);
                renderViews(data);
                pages = data.pages;
                products = data.list;
            });

            // 当屏幕滚动到最底部时执行函数
            $(window).scroll(function () {
                // 判断是否到底部
                if(isEnd()){
                    // 判断是否有下一页
                    if(currentPage < pages){
                        // currentPage +1 , 发送ajax请求获取下一页商品
                        currentPage++;
                        var args = {state:1,currentPage:currentPage, pageSize:4};
                        $.get("/products", args, function (data) {
                            // 返回的数据只有翻页后的数据，没有当前页的数据，直接渲染原来的数据就没有了
                            // 原来的数据+当前的数据
                            $.merge(products, data.list);
                            renderViews({list:products});
                        },"json");
                    } else {
                        $(document).dialog({
                            type:"notice",
                            infoText:"已经到底部了",
                            autoClose:2500,
                            position:"bottom"

                        });
                    }
                }
            });
        });

        function renderViews(data) {
            $(".products").renderValues(data, {
                handle:function (ele, value) {
                    $(ele).attr("href", "/mine/goodsDescribed.html?id="+value);
                }
            });
        };
    </script>
    <style>
        .shop-icon {
            border: 1px solid #80aaff;
            color: #fff;
            display: inline-block;
            float: left;
            margin-left: 19px;
            margin-right: 10px;
            line-height: 12px;
            padding: 2px 6px;
            background: #80aaff;
            margin-top: 3px;
            margin-bottom: 3px;
            font-size: 12px;

        }
    </style>

</head>
<body>
<div class="nav-search">
    <a href="profiles.html">
        <span><i class="fa fa-angle-left fa-2x" ></i></span>
    </a>
</div>
<hr>
<span class="shop-icon">积分商城</span>
<br>
<div class="row products" style="width: 100%; margin: 0 auto;">
    <div class="col-md-12">
        <!--<ol class="breadcrumb">-->
            <!--<li><h2 class="hot">本周热销榜</h2></li>-->
        <!--</ol>-->
        <a><h2 class="hot">本周热销榜</h2></a>
        <h2>
            <span class="buy">大家都在买</span></h2>
        </h2>
    </div>
    <hr>

    <div id="allProducts" render-loop="list" style="margin-top: 10px">
        <!--要循环的每个商品-->
        <div class="col-md-6" style="display:inline-block;margin-bottom: 25px">
            <a href="goodsDescribed.html" render-key="list.id" render-fun="handle">
                <img render-src="list.coverUrl" src=""
                     width="170px" height="170px" style="display: inline-block;">
            </a>
            <div style="width: 170px;margin-bottom: 6px;">

                <a href="goodsDescribed.html" render-key="list.id" render-fun="handle" style='color: #D99531'>
                    <p render-html="list.name"></p>
                </a>

            </div>
            <span class="text">积分兑换：<b>¥&nbsp;</b></span><b render-html="list.price"></b>
        </div>
    </div>


</div>

</body>
</html>